home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / Vector3.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-25  |  2.3 KB  |  86 lines

  1.  
  2. #ifndef __VECTOR3_H_
  3. #define __VECTOR3_H_
  4. /*
  5. Peon - Win32 Games Programming Library
  6. Copyright (C) 2002-2005 Erik Yuzwa
  7.  
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12.  
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with this library; if not, write to the Free
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  
  22. Erik Yuzwa
  23. peon AT wazooinc DOT com
  24. */
  25.  
  26. #include "Peonstdafx.h"
  27.  
  28. namespace peon 
  29. {
  30.  
  31.     /**
  32.     * This object is used to represent a 3-tuple entity for use mostly during
  33.     * object positioning in a 3D gameworld. It's perfectly acceptable to keep
  34.     * the z-plane variable to 1.0f, if you're only interested in using 2D
  35.     * graphics.
  36.     */
  37.     class PEONMAIN_API Vector3
  38.     {
  39.     public:
  40.  
  41.         /** x component */
  42.         float x;
  43.  
  44.         /** y component */
  45.         float y;
  46.  
  47.         /** z component */
  48.         float z;
  49.  
  50.   
  51.         Vector3(float x_ = 0.0f, float y_ = 0.0f, float z_ = 0.0f);
  52.         ~Vector3();
  53.  
  54.         void set(float x_, float y_, float z_);
  55.         float length(void);
  56.         void normalize(void);
  57.  
  58.         // Static utility methods
  59.         static float distance(const Vector3 &v1, const Vector3 &v2);
  60.         static float dotProduct(const Vector3 &v1,  const Vector3 &v2 );
  61.         static Vector3 crossProduct(const Vector3 &v1, const Vector3 &v2);
  62.  
  63.         // Operators...
  64.         Vector3 operator + (const Vector3 &other);
  65.         Vector3 operator - (const Vector3 &other);
  66.         Vector3 operator * (const Vector3 &other);
  67.         Vector3 operator / (const Vector3 &other);
  68.  
  69.         Vector3 operator * (const float scalar);
  70.         friend Vector3 operator * (const float scalar, const Vector3 &other);
  71.     
  72.         Vector3& operator = (const Vector3 &other);
  73.         Vector3& operator += (const Vector3 &other);
  74.         Vector3& operator -= (const Vector3 &other);
  75.  
  76.         Vector3 operator + (void) const;
  77.         Vector3 operator - (void) const;
  78.     };
  79.  
  80.  
  81.  
  82. }
  83.  
  84. #endif
  85.  
  86.